/*
 * Copyright (c) 2025 HiSilicon (Shanghai) Technologies Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef OT_AF_COMMON_H
#define OT_AF_COMMON_H

#include <stdint.h>
#include <stdbool.h>
#include "ot_type.h"
#include "ot_af_tuning_info.h"

#define MODULE_NAME_AF "AUTO_FOCUS"

#define MAX_FLEXIBLE_WINDOW_NUM (8)
#define MAX_FIXED_WINDOW_WIDTH_NUM (28)
#define MAX_FIXED_WINDOW_HEIGHT_NUM (15)

typedef struct {
    td_float zoom;
    td_u32 iso;
    td_s32 apertureCode;
} OT_AF_OpticsInfo;

typedef struct {
    td_u32  maxHCount;  ///< Maximum total number of supported horizontal regions.
    td_u32  maxVCount;  ///< Maximum total number of supported vertical regions.
} OT_AF_FixedWindowCapability;

typedef struct {
    td_u32  maxWindowCount;         ///< Number of floating windows supported.
} OT_AF_FlexibleWindowCapability;

typedef struct {
    OT_AF_FixedWindowCapability fixedWinCapability;
    OT_AF_FlexibleWindowCapability flexWinCapability;
} OT_AF_WindowCapability;

typedef struct {
    td_u32 x; /* left top point x */
    td_u32 y; /* left top point y */
    td_u32 width;
    td_u32 height;
    td_u32 weight;
} OT_AF_FocusWindow;

typedef struct {
    td_bool enable;
    td_u16 numX;
    td_u16 numY;
    OT_AF_FocusWindow window;
} OT_AF_FixedConfig;

typedef struct {
    td_bool enable;
    td_bool windowEnable[MAX_FLEXIBLE_WINDOW_NUM];
    OT_AF_FocusWindow windows[MAX_FLEXIBLE_WINDOW_NUM];
} OT_AF_FlexibleConfig;

typedef struct {
    /* fixed window configure */
    OT_AF_FixedConfig fixedConfig;
    /* flexible window configure */
    OT_AF_FlexibleConfig flexibleConfig;
} OT_AF_WindowConfig;

typedef enum {
    OT_AF_ALG_TYPE_CONTRAST = 0,
    OT_AF_ALG_TYPE_PD,
    OT_AF_ALG_TYPE_TOF,
    OT_AF_ALG_TYPE_LASER,
    OT_AF_ALG_TYPE_BUTT
} OT_AF_AlgType;

typedef struct {
    td_float *dcc;
    td_float *offset;
} OT_AF_PDAFCaliData;

typedef struct {
    td_u8 name[0x16];
    OT_AF_AlgType type;
} OT_AF_AlgInfo;

typedef enum {
    OT_AF_ZOOM_OPTICAL,
    OT_AF_ZOOM_BUTT,
} OT_AF_ZoomType;

typedef enum {
    OT_AF_ZOOM_POLICY_STABLE = 0,
    OT_AF_ZOOM_POLICY_TRACKING,
    OT_AF_ZOOM_POLICY_BUTT,
} OT_AF_ZoomPolicy;

typedef struct {
    OT_AF_ZoomType zoomType;
    OT_AF_ZoomPolicy policy;
    td_float zoom;
    td_float fNum;
    td_s32 apertureCode;
} OT_AF_ZoomInfo;

typedef struct {
    td_u32 rawPipeId;
    td_u32 ppPipeId;
    OT_AF_TuningInfo tuningInfo;
} OT_AF_InitParam;

#endif
